﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Collections;
using GPCSC.Web;
using NickLee.Common;


namespace GPCSC.Web.sjs
{
    public partial class jjwtEdit : PageBase 
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                string sdf = Usual.f_querystringToString("newsid");
                if (sdf != "" && sdf != null)
                {
                    f_bund(sdf);
                }
                else
                {
                    this.Button2.Visible = true;
                    this.Button3.Visible = false;
                }
            }
        }
        protected void f_bund(string ids)
        {
            DataSet ds = new DataSet();
            Hashtable htable = new Hashtable();
            htable.Add("@ids",ids);
            ds = new SqlReadXml().ReaderDataSet("sel_wt_byids", htable);
            if (ds != null)
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                   this.MtxtD_wtvalue.Value = ds.Tables[0].Rows[0]["wtvalue"].ToString();

                    this.MtxtD_wttex.Value = ds.Tables[0].Rows[0]["wttex"].ToString().Replace("^","\n");
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        if (dr["jutext"].ToString() == "1")
                        {
                            dr["jutext"] = "农村";
                        }
                        else if (dr["jutext"].ToString() == "2")
                        {
                            dr["jutext"] = "社区";
                        }
                        else if (dr["jutext"].ToString() == "3")
                        {
                            dr["jutext"] = "企业";
                        }
                    }
                  //  this.types.Items.FindByText(ds.Tables[0].Rows[0]["jutext"].ToString());
                    
                    
                }
            }
            string types = Usual.f_querystringToString("command");
            if (types == "view")
            {
                //this.Button1.Visible = false;
                this.Button2.Visible = false;
                this.Button3.Visible = false;
                UIFactory.UIFactory_ReadOnly(this);
            }
            else if (types == "edit")
            {
                //this.Button1.Visible = false;
                this.Button2.Visible = false;
                this.Button3.Visible = true;
                
            }
        }


        //已解决
        protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {

                Hashtable htable = new Hashtable();
                byte[] userInfo = (byte[])base.o_baseTable[c_obj.s_userInfo];
                Hashtable userInfoTable = CompressData.UnCompressHashtable(userInfo);
                Model.CL_USER_S users = (Model.CL_USER_S)userInfoTable["SYS_USER"];
                base.o_uiTable.Clear();
                base.o_uiTable = UIFactory.UIFactory_Get(this);
                SQLServerDAL.databyhtable dtable = new SQLServerDAL.databyhtable();

                base.o_uiTable.Add("tjdate",DateTime.Now.ToString());

                base.o_uiTable.Add("jjdate", DateTime.Now.ToString());
                base.o_uiTable.Add("juvalue", "1");
                base.o_uiTable.Add("lgid", users.CL_USER_SOID.ToString());
                string types = this.types.Value.ToString();
                base.o_uiTable.Add("jutext", types);
                string typ = this.type.Value.ToString();
                base.o_uiTable.Add("typ", typ);
                dtable.databyhtables(base.o_uiTable, "add", "wts_table", "", "");

                this.Response.Write("<script>alert('添加成功！');window.location.href='jjwtlist.aspx';</script>");
            }
            catch (Exception ee)
            {
                throw ee;
            }
        }


        //未解决
        protected void Button2_Click(object sender, EventArgs e)
        {
            try
            {
                Hashtable htable = new Hashtable();
                byte[] userInfo = (byte[])base.o_baseTable[c_obj.s_userInfo];
                Hashtable userInfoTable = CompressData.UnCompressHashtable(userInfo);
                Model.CL_USER_S users = (Model.CL_USER_S)userInfoTable["SYS_USER"];
                base.o_uiTable.Clear();
                base.o_uiTable = UIFactory.UIFactory_Get(this);
                SQLServerDAL.databyhtable dtable = new SQLServerDAL.databyhtable();
                base.o_uiTable.Add("tjdate", DateTime.Now.ToString());
                base.o_uiTable.Add("lgid", users.CL_USER_SOID.ToString());
                string types = this.types.Value.ToString();
                base.o_uiTable.Add("jutext", types);
                base.o_uiTable.Add("juvalue", "0");
                base.o_uiTable.Add("wtvalue", MtxtD_wtvalue.Value);
                base.o_uiTable.Add("wttex", MtxtD_wttex.Value.Replace("\n","^"));
                string typ = this.type.Value.ToString();
                base.o_uiTable.Add("typ", typ);
                base.o_uiTable.Add("Postid", users.CL_POSTID_PK.ToString());
                
                dtable.databyhtables(base.o_uiTable, "add", "wts_table", "", "");

                this.Response.Write("<script>alert('添加成功！');window.location.href='jjwtlist.aspx';</script>");
            }
            catch 
            {
                Hashtable htable = new Hashtable();
                byte[] userInfo = (byte[])base.o_baseTable[c_obj.s_userInfo];
                Hashtable userInfoTable = CompressData.UnCompressHashtable(userInfo);
                Model.CL_USER_S users = (Model.CL_USER_S)userInfoTable["SYS_USER"];
                base.o_uiTable.Clear();
                base.o_uiTable = UIFactory.UIFactory_Get(this);
                SQLServerDAL.databyhtable dtable = new SQLServerDAL.databyhtable();
                base.o_uiTable.Add("tjdate", DateTime.Now.ToString());
                base.o_uiTable.Add("lgid", users.CL_USER_SOID.ToString());
                string types = this.types.Value.ToString();
                base.o_uiTable.Add("jutext", types);
                base.o_uiTable.Add("juvalue", "0");
                base.o_uiTable.Add("wtvalue", MtxtD_wtvalue.Value);
                base.o_uiTable.Add("wttex", new NotHTML().NoHTML(MtxtD_wttex.Value));
                string typ = this.type.Value.ToString();
                base.o_uiTable.Add("typ", typ);
                base.o_uiTable.Add("Postid", users.CL_POSTID_PK.ToString());

                dtable.databyhtables(base.o_uiTable, "add", "wts_table", "", "");

                this.Response.Write("<script>alert('添加成功！');window.location.href='jjwtlist.aspx';</script>");
            }
        }

        //修改
        protected void Button3_Click(object sender, EventArgs e)
        {
            try
            {
                string ids = Usual.f_querystringToString("newsid");
                base.o_uiTable.Clear();
                base.o_uiTable = UIFactory.UIFactory_Get(this);
                string types = this.types.Value.ToString();
                base.o_uiTable.Add("jutext", types);
                base.o_uiTable.Add("wtvalue", MtxtD_wtvalue.Value);
                base.o_uiTable.Add("wttex", MtxtD_wttex.Value.Replace("\n", "^"));
                string typ = this.type.Value.ToString();
                base.o_uiTable.Add("typ", typ);
                SQLServerDAL.databyhtable dtable = new SQLServerDAL.databyhtable();
                dtable.databyhtables(base.o_uiTable, "update", "wts_table", "hdwt_id", ids);
                this.Response.Write("<script>alert('修改成功！');window.location.href='jjwtlist.aspx';</script>");
            }
            catch
            {
                string ids = Usual.f_querystringToString("newsid");
                base.o_uiTable.Clear();
                base.o_uiTable = UIFactory.UIFactory_Get(this);
                string types = this.types.Value.ToString();
                base.o_uiTable.Add("jutext", types);
                base.o_uiTable.Add("wtvalue", MtxtD_wtvalue.Value);
                base.o_uiTable.Add("wttex", new NotHTML().NoHTML(MtxtD_wttex.Value));
                string typ = this.type.Value.ToString();
                base.o_uiTable.Add("typ", typ);
                SQLServerDAL.databyhtable dtable = new SQLServerDAL.databyhtable();
                dtable.databyhtables(base.o_uiTable, "update", "wts_table", "hdwt_id", ids);
                this.Response.Write("<script>alert('修改成功！');window.location.href='jjwtlist.aspx';</script>");
            }
        }

    }
}